From 390a42fa605e99362ac307bf568113dcdad41cdc Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Thu, 12 Feb 2015 14:28:22 +0000 Subject: [PATCH] gl: Add gdk_gl_context_get_version() Store the OpenGL version when we first do the extensions check; this allows client code to check the available GL version without requiring a call to gdk_gl_context_make_current() and epoxy_gl_version(). --- docs/reference/gdk/gdk3-sections.txt | 5 ++++ gdk/gdkglcontext.c | 35 +++++++++++++++++++++++++++- gdk/gdkglcontext.h | 4 ++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/docs/reference/gdk/gdk3-sections.txt b/docs/reference/gdk/gdk3-sections.txt index e90b782731..7335636bd5 100644 --- a/docs/reference/gdk/gdk3-sections.txt +++ b/docs/reference/gdk/gdk3-sections.txt @@ -1291,6 +1291,9 @@ GdkGLContext gdk_gl_context_get_display gdk_gl_context_get_window gdk_gl_context_get_shared_context +gdk_gl_context_get_version + + gdk_gl_context_set_required_version gdk_gl_context_get_required_version gdk_gl_context_set_debug_enabled @@ -1300,6 +1303,8 @@ gdk_gl_context_get_forward_compatible GdkGLProfile gdk_gl_context_set_profile gdk_gl_context_get_profile + + GdkGLError gdk_gl_context_realize gdk_gl_context_make_current diff --git a/gdk/gdkglcontext.c b/gdk/gdkglcontext.c index ec6c0a53f9..1ffacca43f 100644 --- a/gdk/gdkglcontext.c +++ b/gdk/gdkglcontext.c @@ -95,6 +95,7 @@ typedef struct { int major; int minor; + int gl_version; guint realized : 1; guint use_texture_rectangle : 1; @@ -617,6 +618,8 @@ gdk_gl_context_check_extensions (GdkGLContext *context) if (priv->extensions_checked) return; + priv->gl_version = epoxy_gl_version (); + has_npot = epoxy_has_gl_extension ("GL_ARB_texture_non_power_of_two"); has_texture_rectangle = epoxy_has_gl_extension ("GL_ARB_texture_rectangle"); @@ -633,12 +636,14 @@ gdk_gl_context_check_extensions (GdkGLContext *context) g_warning ("GL implementation doesn't support any form of non-power-of-two textures"); GDK_NOTE (OPENGL, - g_print ("Extensions checked:\n" + g_print ("OpenGL version: %d.%d\n" + "Extensions checked:\n" " - GL_ARB_texture_non_power_of_two: %s\n" " - GL_ARB_texture_rectangle: %s\n" " - GL_EXT_framebuffer_blit: %s\n" " - GL_GREMEDY_frame_terminator: %s\n" "Using texture rectangle: %s\n", + priv->gl_version / 10, priv->gl_version % 10, has_npot ? "yes" : "no", has_texture_rectangle ? "yes" : "no", priv->has_gl_framebuffer_blit ? "yes" : "no", @@ -798,6 +803,34 @@ gdk_gl_context_get_shared_context (GdkGLContext *context) return priv->shared_context; } +/** + * gdk_gl_context_get_version: + * @context: a #GdkGLContext + * @major: (out): return location for the major version + * @minor: (out): return location for the minor version + * + * Retrieves the OpenGL version of the @context. + * + * The @context must be realized prior to calling this function. + * + * Since: 3.16 + */ +void +gdk_gl_context_get_version (GdkGLContext *context, + int *major, + int *minor) +{ + GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context); + + g_return_if_fail (GDK_IS_GL_CONTEXT (context)); + g_return_if_fail (priv->realized); + + if (major != NULL) + *major = priv->gl_version / 10; + if (minor != NULL) + *minor = priv->gl_version % 10; +} + /** * gdk_gl_context_clear_current: * diff --git a/gdk/gdkglcontext.h b/gdk/gdkglcontext.h index d6d5f39333..089d746c39 100644 --- a/gdk/gdkglcontext.h +++ b/gdk/gdkglcontext.h @@ -48,6 +48,10 @@ GDK_AVAILABLE_IN_3_16 GdkWindow * gdk_gl_context_get_window (GdkGLContext *context); GDK_AVAILABLE_IN_3_16 GdkGLContext * gdk_gl_context_get_shared_context (GdkGLContext *context); +GDK_AVAILABLE_IN_3_16 +void gdk_gl_context_get_version (GdkGLContext *context, + int *major, + int *minor); GDK_AVAILABLE_IN_3_16 void gdk_gl_context_set_required_version (GdkGLContext *context, -- 2.30.2